import { SubjectComponent } from "../core/subject";
import RadioGroup2 from "./radio_group2";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TabView2 extends SubjectComponent {
    @property(RadioGroup2)
    rg2: RadioGroup2 = null;
    @property([cc.Node])
    pages: cc.Node[] = [];
    @property
    curInd = 0;
    onLoad() {
        this.pages.forEach((page, ind) => {
            page.active = this.curInd === ind;
        });
    }
    onSelect(ind) {
        this.sel(ind);
    }
    start() {
        this.rg2.on("select", this.onSelect, this);
        this.sel(this.curInd, true);
    }
    sel(ind: number, silent = false) {
        this.curInd = ind;
        this.pages.forEach((page, ind) => {
            page.active = this.curInd === ind;
        });
        if (!silent) {
            this.emit("select", this);
        }
    }
};